package action;

import bean.GoodsVo;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;

import dao.GoodsDAO;

public class GetAllGoods extends ActionSupport {

	public String getAllGoods(){
		HttpServletRequest req = ServletActionContext.getRequest();
		String pageNo = req.getParameter("pageNo");
		System.out.println(pageNo);
		int page = 1;
		if (pageNo != null){
			page = Integer.parseInt(pageNo);
		}

		GoodsDAO goodsDAO = new GoodsDAO();
		ArrayList<GoodsVo> goodsList = goodsDAO.getGoodsByPage(page);

		for (int i = 0; i < goodsList.size(); i++){
			System.out.println(goodsList.get(i).getGoodsName());
		}
		int pageCount = goodsDAO.getPageCount();

		ActionContext.getContext().put("goodsList",goodsList);
		ActionContext.getContext().put("pageNo", page);
		ActionContext.getContext().put("pageCount", pageCount);

		return SUCCESS;
	}
}
